(use ./netfunc ./common)
(def cfg {:host "127.0.0.1" :port 4055
         :client1-port 4056})

(defn server {:host host :port port}
  (def guess-state :client1)

  (varfn guess-server (num &opt game-token)
    (assert (number? num) "Invalid value; must be number between 0 and 255.")
    (if (get game game-token)
      (do
        (def session (get game game-token))
        (cond (= num (session :n)) (do
                                     (set (session :state) :won)
                                     (string/format "Game won! Number was %n" (session :n)))
              (= :won (session :state)) (string/format "Game won! Number was %n" (session :n))
              (string/format "%ser than %n" (if (< (session :n) num) "Small" "Bigg") num)))
      (do
        (default game-token os/cryptorand 8)
        (default num ;(string/bytes (os/cryptorand 1)))
        (assert (<= 0 num 255) "Invalid number; must be between 0 and 255.")
        (set (game game-token) @{:n num})
        {:token game-token :meta {:call-back-in 2}})))
  (varfn guess-client ({:token game-token})
    (print ) #TODO
    (def n)
    n
    )

      (def stream-init (netfn guess-init host port))
